package bpmn.diagram.part;

import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.View;

import bpmn.BpmnPackage;
import bpmn.End;
import bpmn.Intermediate;
import bpmn.Process;
import bpmn.Start;
import bpmn.Task;
import bpmn.diagram.edit.parts.AssociationEditPart;
import bpmn.diagram.edit.parts.ComplexEditPart;
import bpmn.diagram.edit.parts.DataBasedEditPart;
import bpmn.diagram.edit.parts.DataObjectEditPart;
import bpmn.diagram.edit.parts.DataObjectNameEditPart;
import bpmn.diagram.edit.parts.EndEditPart;
import bpmn.diagram.edit.parts.InclusiveEditPart;
import bpmn.diagram.edit.parts.IntermediateEditPart;
import bpmn.diagram.edit.parts.Lane2EditPart;
import bpmn.diagram.edit.parts.LaneCompartmentLaneEditPart;
import bpmn.diagram.edit.parts.LaneEditPart;
import bpmn.diagram.edit.parts.LaneName2EditPart;
import bpmn.diagram.edit.parts.LaneNameEditPart;
import bpmn.diagram.edit.parts.ParallelEditPart;
import bpmn.diagram.edit.parts.PoolCompartmentPoolEditPart;
import bpmn.diagram.edit.parts.PoolEditPart;
import bpmn.diagram.edit.parts.Process2EditPart;
import bpmn.diagram.edit.parts.ProcessCompartmentProcessEditPart;
import bpmn.diagram.edit.parts.ProcessEditPart;
import bpmn.diagram.edit.parts.ProcessNameEditPart;
import bpmn.diagram.edit.parts.SequenceFlowEditPart;
import bpmn.diagram.edit.parts.StartEditPart;
import bpmn.diagram.edit.parts.Task2EditPart;
import bpmn.diagram.edit.parts.Task3EditPart;
import bpmn.diagram.edit.parts.Task4EditPart;
import bpmn.diagram.edit.parts.Task5EditPart;
import bpmn.diagram.edit.parts.Task6EditPart;
import bpmn.diagram.edit.parts.Task7EditPart;
import bpmn.diagram.edit.parts.Task8EditPart;
import bpmn.diagram.edit.parts.Task9EditPart;
import bpmn.diagram.edit.parts.TaskEditPart;
import bpmn.diagram.edit.parts.TaskName2EditPart;
import bpmn.diagram.edit.parts.TaskName3EditPart;
import bpmn.diagram.edit.parts.TaskName4EditPart;
import bpmn.diagram.edit.parts.TaskName5EditPart;
import bpmn.diagram.edit.parts.TaskName6EditPart;
import bpmn.diagram.edit.parts.TaskName7EditPart;
import bpmn.diagram.edit.parts.TaskName8EditPart;
import bpmn.diagram.edit.parts.TaskName9EditPart;
import bpmn.diagram.edit.parts.TaskNameEditPart;
import bpmn.diagram.edit.parts.WrappingLabelEditPart;
import bpmn.diagram.expressions.Bpmn_1_1OCLFactory;

/**
 * This registry is used to determine which type of visual object should be
 * created for the corresponding Diagram, Node, ChildNode or Link represented
 * by a domain model object.
 * 
 * @generated
 */
public class Bpmn_1_1VisualIDRegistry {

	/**
	 * @generated
	 */
	private static final String DEBUG_KEY = "GMF-BPMN.diagram/debug/visualID"; //$NON-NLS-1$

	/**
	 * @generated
	 */
	public static int getVisualID(View view) {
		if (view instanceof Diagram) {
			if (ProcessEditPart.MODEL_ID.equals(view.getType())) {
				return ProcessEditPart.VISUAL_ID;
			} else {
				return -1;
			}
		}
		return bpmn.diagram.part.Bpmn_1_1VisualIDRegistry.getVisualID(view
				.getType());
	}

	/**
	 * @generated
	 */
	public static String getModelID(View view) {
		View diagram = view.getDiagram();
		while (view != diagram) {
			EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
			if (annotation != null) {
				return (String) annotation.getDetails().get("modelID"); //$NON-NLS-1$
			}
			view = (View) view.eContainer();
		}
		return diagram != null ? diagram.getType() : null;
	}

	/**
	 * @generated
	 */
	public static int getVisualID(String type) {
		try {
			return Integer.parseInt(type);
		} catch (NumberFormatException e) {
			if (Boolean.TRUE.toString().equalsIgnoreCase(
					Platform.getDebugOption(DEBUG_KEY))) {
				Bpmn_1_1DiagramEditorPlugin.getInstance().logError(
						"Unable to parse view type as a visualID number: "
								+ type);
			}
		}
		return -1;
	}

	/**
	 * @generated
	 */
	public static String getType(int visualID) {
		return Integer.toString(visualID);
	}

	/**
	 * @generated
	 */
	public static int getDiagramVisualID(EObject domainElement) {
		if (domainElement == null) {
			return -1;
		}
		if (BpmnPackage.eINSTANCE.getProcess().isSuperTypeOf(
				domainElement.eClass())
				&& isDiagram((Process) domainElement)) {
			return ProcessEditPart.VISUAL_ID;
		}
		return -1;
	}

	/**
	 * @generated
	 */
	public static int getNodeVisualID(View containerView, EObject domainElement) {
		if (domainElement == null) {
			return -1;
		}
		String containerModelID = bpmn.diagram.part.Bpmn_1_1VisualIDRegistry
				.getModelID(containerView);
		if (!ProcessEditPart.MODEL_ID.equals(containerModelID)) {
			return -1;
		}
		int containerVisualID;
		if (ProcessEditPart.MODEL_ID.equals(containerModelID)) {
			containerVisualID = bpmn.diagram.part.Bpmn_1_1VisualIDRegistry
					.getVisualID(containerView);
		} else {
			if (containerView instanceof Diagram) {
				containerVisualID = ProcessEditPart.VISUAL_ID;
			} else {
				return -1;
			}
		}
		switch (containerVisualID) {
		case ProcessEditPart.VISUAL_ID:
			if (BpmnPackage.eINSTANCE.getPool().isSuperTypeOf(
					domainElement.eClass())) {
				return PoolEditPart.VISUAL_ID;
			}
			break;
		case PoolCompartmentPoolEditPart.VISUAL_ID:
			if (BpmnPackage.eINSTANCE.getProcess().isSuperTypeOf(
					domainElement.eClass())) {
				return Process2EditPart.VISUAL_ID;
			}
			if (BpmnPackage.eINSTANCE.getLane().isSuperTypeOf(
					domainElement.eClass())) {
				return LaneEditPart.VISUAL_ID;
			}
			break;
		case ProcessCompartmentProcessEditPart.VISUAL_ID:
			if (BpmnPackage.eINSTANCE.getTask().isSuperTypeOf(
					domainElement.eClass())
					&& isTask_3002((Task) domainElement)) {
				return TaskEditPart.VISUAL_ID;
			}
			if (BpmnPackage.eINSTANCE.getTask().isSuperTypeOf(
					domainElement.eClass())
					&& isTask_3009((Task) domainElement)) {
				return Task2EditPart.VISUAL_ID;
			}
			if (BpmnPackage.eINSTANCE.getTask().isSuperTypeOf(
					domainElement.eClass())
					&& isTask_3014((Task) domainElement)) {
				return Task3EditPart.VISUAL_ID;
			}
			if (BpmnPackage.eINSTANCE.getTask().isSuperTypeOf(
					domainElement.eClass())
					&& isTask_3015((Task) domainElement)) {
				return Task4EditPart.VISUAL_ID;
			}
			if (BpmnPackage.eINSTANCE.getTask().isSuperTypeOf(
					domainElement.eClass())
					&& isTask_3016((Task) domainElement)) {
				return Task5EditPart.VISUAL_ID;
			}
			if (BpmnPackage.eINSTANCE.getTask().isSuperTypeOf(
					domainElement.eClass())
					&& isTask_3017((Task) domainElement)) {
				return Task6EditPart.VISUAL_ID;
			}
			if (BpmnPackage.eINSTANCE.getTask().isSuperTypeOf(
					domainElement.eClass())
					&& isTask_3018((Task) domainElement)) {
				return Task7EditPart.VISUAL_ID;
			}
			if (BpmnPackage.eINSTANCE.getTask().isSuperTypeOf(
					domainElement.eClass())
					&& isTask_3019((Task) domainElement)) {
				return Task8EditPart.VISUAL_ID;
			}
			if (BpmnPackage.eINSTANCE.getTask().isSuperTypeOf(
					domainElement.eClass())
					&& isTask_3020((Task) domainElement)) {
				return Task9EditPart.VISUAL_ID;
			}
			if (BpmnPackage.eINSTANCE.getStart().isSuperTypeOf(
					domainElement.eClass())
					&& isStart_3003((Start) domainElement)) {
				return StartEditPart.VISUAL_ID;
			}
			if (BpmnPackage.eINSTANCE.getIntermediate().isSuperTypeOf(
					domainElement.eClass())
					&& isIntermediate_3004((Intermediate) domainElement)) {
				return IntermediateEditPart.VISUAL_ID;
			}
			if (BpmnPackage.eINSTANCE.getEnd().isSuperTypeOf(
					domainElement.eClass())
					&& isEnd_3005((End) domainElement)) {
				return EndEditPart.VISUAL_ID;
			}
			if (BpmnPackage.eINSTANCE.getDataObject().isSuperTypeOf(
					domainElement.eClass())) {
				return DataObjectEditPart.VISUAL_ID;
			}
			if (BpmnPackage.eINSTANCE.getInclusive().isSuperTypeOf(
					domainElement.eClass())) {
				return InclusiveEditPart.VISUAL_ID;
			}
			if (BpmnPackage.eINSTANCE.getComplex().isSuperTypeOf(
					domainElement.eClass())) {
				return ComplexEditPart.VISUAL_ID;
			}
			if (BpmnPackage.eINSTANCE.getParallel().isSuperTypeOf(
					domainElement.eClass())) {
				return ParallelEditPart.VISUAL_ID;
			}
			if (BpmnPackage.eINSTANCE.getDataBased().isSuperTypeOf(
					domainElement.eClass())) {
				return DataBasedEditPart.VISUAL_ID;
			}
			break;
		case LaneCompartmentLaneEditPart.VISUAL_ID:
			if (BpmnPackage.eINSTANCE.getLane().isSuperTypeOf(
					domainElement.eClass())) {
				return Lane2EditPart.VISUAL_ID;
			}
			break;
		}
		return -1;
	}

	/**
	 * @generated
	 */
	public static boolean canCreateNode(View containerView, int nodeVisualID) {
		String containerModelID = bpmn.diagram.part.Bpmn_1_1VisualIDRegistry
				.getModelID(containerView);
		if (!ProcessEditPart.MODEL_ID.equals(containerModelID)) {
			return false;
		}
		int containerVisualID;
		if (ProcessEditPart.MODEL_ID.equals(containerModelID)) {
			containerVisualID = bpmn.diagram.part.Bpmn_1_1VisualIDRegistry
					.getVisualID(containerView);
		} else {
			if (containerView instanceof Diagram) {
				containerVisualID = ProcessEditPart.VISUAL_ID;
			} else {
				return false;
			}
		}
		switch (containerVisualID) {
		case ProcessEditPart.VISUAL_ID:
			if (PoolEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case PoolEditPart.VISUAL_ID:
			if (WrappingLabelEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (PoolCompartmentPoolEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case Process2EditPart.VISUAL_ID:
			if (ProcessNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (ProcessCompartmentProcessEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case TaskEditPart.VISUAL_ID:
			if (TaskNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case Task2EditPart.VISUAL_ID:
			if (TaskName2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case Task3EditPart.VISUAL_ID:
			if (TaskName3EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case Task4EditPart.VISUAL_ID:
			if (TaskName4EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case Task5EditPart.VISUAL_ID:
			if (TaskName5EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case Task6EditPart.VISUAL_ID:
			if (TaskName6EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case Task7EditPart.VISUAL_ID:
			if (TaskName7EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case Task8EditPart.VISUAL_ID:
			if (TaskName8EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case Task9EditPart.VISUAL_ID:
			if (TaskName9EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case DataObjectEditPart.VISUAL_ID:
			if (DataObjectNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case LaneEditPart.VISUAL_ID:
			if (LaneNameEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (LaneCompartmentLaneEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case Lane2EditPart.VISUAL_ID:
			if (LaneName2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case PoolCompartmentPoolEditPart.VISUAL_ID:
			if (Process2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (LaneEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case ProcessCompartmentProcessEditPart.VISUAL_ID:
			if (TaskEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (Task2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (Task3EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (Task4EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (Task5EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (Task6EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (Task7EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (Task8EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (Task9EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (StartEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (IntermediateEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (EndEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (DataObjectEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (InclusiveEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (ComplexEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (ParallelEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			if (DataBasedEditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		case LaneCompartmentLaneEditPart.VISUAL_ID:
			if (Lane2EditPart.VISUAL_ID == nodeVisualID) {
				return true;
			}
			break;
		}
		return false;
	}

	/**
	 * @generated
	 */
	public static int getLinkWithClassVisualID(EObject domainElement) {
		if (domainElement == null) {
			return -1;
		}
		if (BpmnPackage.eINSTANCE.getSequenceFlow().isSuperTypeOf(
				domainElement.eClass())) {
			return SequenceFlowEditPart.VISUAL_ID;
		}
		if (BpmnPackage.eINSTANCE.getAssociation().isSuperTypeOf(
				domainElement.eClass())) {
			return AssociationEditPart.VISUAL_ID;
		}
		return -1;
	}

	/**
	 * User can change implementation of this method to handle some specific
	 * situations not covered by default logic.
	 * 
	 * @generated
	 */
	private static boolean isDiagram(Process element) {
		return true;
	}

	/**
	 * @generated
	 */
	private static boolean isTask_3002(Task domainElement) {
		Object result = Bpmn_1_1OCLFactory.getExpression(0,
				BpmnPackage.eINSTANCE.getTask(), null).evaluate(domainElement);
		return result instanceof Boolean && ((Boolean) result).booleanValue();
	}

	/**
	 * @generated
	 */
	private static boolean isTask_3009(Task domainElement) {
		Object result = Bpmn_1_1OCLFactory.getExpression(2,
				BpmnPackage.eINSTANCE.getTask(), null).evaluate(domainElement);
		return result instanceof Boolean && ((Boolean) result).booleanValue();
	}

	/**
	 * @generated
	 */
	private static boolean isTask_3014(Task domainElement) {
		Object result = Bpmn_1_1OCLFactory.getExpression(4,
				BpmnPackage.eINSTANCE.getTask(), null).evaluate(domainElement);
		return result instanceof Boolean && ((Boolean) result).booleanValue();
	}

	/**
	 * @generated
	 */
	private static boolean isTask_3015(Task domainElement) {
		Object result = Bpmn_1_1OCLFactory.getExpression(6,
				BpmnPackage.eINSTANCE.getTask(), null).evaluate(domainElement);
		return result instanceof Boolean && ((Boolean) result).booleanValue();
	}

	/**
	 * @generated
	 */
	private static boolean isTask_3016(Task domainElement) {
		Object result = Bpmn_1_1OCLFactory.getExpression(8,
				BpmnPackage.eINSTANCE.getTask(), null).evaluate(domainElement);
		return result instanceof Boolean && ((Boolean) result).booleanValue();
	}

	/**
	 * @generated
	 */
	private static boolean isTask_3017(Task domainElement) {
		Object result = Bpmn_1_1OCLFactory.getExpression(10,
				BpmnPackage.eINSTANCE.getTask(), null).evaluate(domainElement);
		return result instanceof Boolean && ((Boolean) result).booleanValue();
	}

	/**
	 * @generated
	 */
	private static boolean isTask_3018(Task domainElement) {
		Object result = Bpmn_1_1OCLFactory.getExpression(12,
				BpmnPackage.eINSTANCE.getTask(), null).evaluate(domainElement);
		return result instanceof Boolean && ((Boolean) result).booleanValue();
	}

	/**
	 * @generated
	 */
	private static boolean isTask_3019(Task domainElement) {
		Object result = Bpmn_1_1OCLFactory.getExpression(14,
				BpmnPackage.eINSTANCE.getTask(), null).evaluate(domainElement);
		return result instanceof Boolean && ((Boolean) result).booleanValue();
	}

	/**
	 * @generated
	 */
	private static boolean isTask_3020(Task domainElement) {
		Object result = Bpmn_1_1OCLFactory.getExpression(16,
				BpmnPackage.eINSTANCE.getTask(), null).evaluate(domainElement);
		return result instanceof Boolean && ((Boolean) result).booleanValue();
	}

	/**
	 * @generated
	 */
	private static boolean isStart_3003(Start domainElement) {
		Object result = Bpmn_1_1OCLFactory.getExpression(18,
				BpmnPackage.eINSTANCE.getStart(), null).evaluate(domainElement);
		return result instanceof Boolean && ((Boolean) result).booleanValue();
	}

	/**
	 * @generated
	 */
	private static boolean isIntermediate_3004(Intermediate domainElement) {
		Object result = Bpmn_1_1OCLFactory.getExpression(19,
				BpmnPackage.eINSTANCE.getIntermediate(), null).evaluate(
				domainElement);
		return result instanceof Boolean && ((Boolean) result).booleanValue();
	}

	/**
	 * @generated
	 */
	private static boolean isEnd_3005(End domainElement) {
		Object result = Bpmn_1_1OCLFactory.getExpression(21,
				BpmnPackage.eINSTANCE.getEnd(), null).evaluate(domainElement);
		return result instanceof Boolean && ((Boolean) result).booleanValue();
	}

}
